package root.electronclass.electronclass.personal.dialog

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import root.electronclass.electronclass.common.base.BasicAdapter
import root.electronclass.electronclass.common.base.BasicDialogFragment
import root.electronclass.electronclass.mvp.entity.MoralScoreRecord
import root.electronclass.electronclass.mvp.entity.PicDto
import root.electronclass.electronclass.App
import root.electronclass.electronclass.databinding.DialogMoralSpaceScoreDesBinding
import root.electronclass.electronclass.databinding.ItemCharacterDetailsDialogBinding
import root.electronclass.electronclass.ext.setVideoThumbnail
import root.electronclass.electronclass.other.PictureActivity
import root.electronclass.electronclass.other.VideoActivity

/**
 *
 * @author Lokiy
 * @date 2023/2/18 21:10
 */
class CharacterDetailDialog : BasicDialogFragment<DialogMoralSpaceScoreDesBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        binding.update(arguments?.getParcelable(DATA) ?: return)
    }

    companion object {
        const val DATA = "_DATA"
    }

}

fun DialogMoralSpaceScoreDesBinding.update(it: MoralScoreRecord) {
    val layout =LinearLayoutManager(App.app, LinearLayoutManager.HORIZONTAL, false)
    val layout1 =LinearLayoutManager(App.app, LinearLayoutManager.HORIZONTAL, false)
    rcvPic.layoutManager = layout
    rcvPic.adapter = adapter1
    rcvVideo.layoutManager = layout1
    rcvVideo.adapter = adapter2
    if (it.pictureUrlFormat != null && it.pictureUrlFormat.orEmpty().size > 0) {
        adapter1.notifyChanged(it.pictureUrlFormat)
    }
    if (it.videoFormat != null && it.videoFormat.orEmpty().size > 0) {
        adapter2.notifyChanged(it.videoFormat)
    }
    remarks.text = it.remark
}

private val adapter1 = BasicAdapter<PicDto, ItemCharacterDetailsDialogBinding> { holder, item ->
    holder.binding.pic.setImageURI(item.url)
    holder.binding.pic.setOnClickListener {
        val lists = ArrayList<String>()
        for (i in list){
            lists.add(i.url.orEmpty())
        }
        PictureActivity.startActivity(App.app, lists,0)
    }
}


private val adapter2 = BasicAdapter<PicDto, ItemCharacterDetailsDialogBinding> { holder, item ->
    holder.binding.pic.setVideoThumbnail(item.url)
    holder.binding.pic.setOnClickListener {
        VideoActivity.startActivity(App.app,item.url.orEmpty())
    }
}

